#!/bin/sh

# stage1 needs this
mkdir -p /image

# remove all docs
rm -rf /usr/share/{doc,man,info,license,gfxboot}

# remove images
rm -rf /usr/share/icons/{hicolor,large,mini}

# remove PAM plugins
rm -rf /lib*/security

# remove cpp
rpmquery -a cpp\* gcc\* perl-base |
	xargs -r rpmi -e --nodeps --

# remove X11 dri modules
rm -rf /usr/lib*/X11/modules/dri
rm -rf /usr/lib*/X11/modules/multimedia
rm -rf /usr/lib*/X11/mesa_gl

rm -f /usr/lib*/X11/modules/extensions/libglx.so
rm -f /usr/lib*/X11/modules/extensions/libdri.so
rm -f /usr/lib*/X11/modules/extensions/libGLcore.so

# remove unneeded kernel modules (keep firmware though)
rm -rf /lib/modules/*/kernel/arch
rm -rf /lib/modules/*/kernel/crypto
rm -rf /lib/modules/*/kernel/drivers/atm
rm -rf /lib/modules/*/kernel/drivers/char/watchdog
rm -rf /lib/modules/*/kernel/drivers/cpufreq
rm -rf /lib/modules/*/kernel/drivers/edac
rm -rf /lib/modules/*/kernel/drivers/hwmon
rm -rf /lib/modules/*/kernel/drivers/infiniband
rm -rf /lib/modules/*/kernel/drivers/input/{gameport,joy*}
rm -rf /lib/modules/*/kernel/drivers/isdn
rm -rf /lib/modules/*/kernel/drivers/media
rm -rf /lib/modules/*/kernel/drivers/mmc
rm -rf /lib/modules/*/kernel/drivers/mtd*
rm -rf /lib/modules/*/kernel/drivers/net/irda
rm -rf /lib/modules/*/kernel/drivers/rtc
rm -rf /lib/modules/*/kernel/drivers/spi
rm -rf /lib/modules/*/kernel/drivers/telephony
rm -rf /lib/modules/*/kernel/drivers/usb/{misc,mon}
rm -rf /lib/modules/*/kernel/drivers/video
rm -rf /lib/modules/*/kernel/drivers/bluetooth
rm -rf /lib/modules/*/kernel/drivers/ieee1394
rm -rf /lib/modules/*/kernel/drivers/w1
rm -rf /lib/modules/*/kernel/fs/quota*
rm -rf /lib/modules/*/kernel/fs/9p
rm -rf /lib/modules/*/kernel/fs/adfs
rm -rf /lib/modules/*/kernel/fs/affs
rm -rf /lib/modules/*/kernel/fs/afs
rm -rf /lib/modules/*/kernel/fs/autofs
rm -rf /lib/modules/*/kernel/fs/autofs4
rm -rf /lib/modules/*/kernel/fs/befs
rm -rf /lib/modules/*/kernel/fs/bfs
rm -rf /lib/modules/*/kernel/fs/cifs
rm -rf /lib/modules/*/kernel/fs/coda
rm -rf /lib/modules/*/kernel/fs/configfs
rm -rf /lib/modules/*/kernel/fs/cramfs
rm -rf /lib/modules/*/kernel/fs/efs
rm -rf /lib/modules/*/kernel/fs/exportfs
rm -rf /lib/modules/*/kernel/fs/freevxfs
rm -rf /lib/modules/*/kernel/fs/fuse
rm -rf /lib/modules/*/kernel/fs/hfs
rm -rf /lib/modules/*/kernel/fs/hfsplus
rm -rf /lib/modules/*/kernel/fs/hpfs
rm -rf /lib/modules/*/kernel/fs/jffs
rm -rf /lib/modules/*/kernel/fs/jffs2
rm -rf /lib/modules/*/kernel/fs/lockd
rm -rf /lib/modules/*/kernel/fs/minix
rm -rf /lib/modules/*/kernel/fs/ncpfs
rm -rf /lib/modules/*/kernel/fs/ocfs2
rm -rf /lib/modules/*/kernel/fs/qnx4
rm -rf /lib/modules/*/kernel/fs/smbfs
rm -rf /lib/modules/*/kernel/fs/sysv
rm -rf /lib/modules/*/kernel/fs/udf
rm -rf /lib/modules/*/kernel/fs/ufs
rm -rf /lib/modules/*/kernel/fs/ecryptfs
rm -rf /lib/modules/*/kernel/net/*/netfilter
rm -rf /lib/modules/*/kernel/net/appletalk
rm -rf /lib/modules/*/kernel/net/ax25
rm -rf /lib/modules/*/kernel/net/bluetooth
rm -rf /lib/modules/*/kernel/net/bridge
rm -rf /lib/modules/*/kernel/net/dccp
rm -rf /lib/modules/*/kernel/net/decnet
rm -rf /lib/modules/*/kernel/net/econet
rm -rf /lib/modules/*/kernel/net/ipv6
rm -rf /lib/modules/*/kernel/net/ipx
rm -rf /lib/modules/*/kernel/net/irda
rm -rf /lib/modules/*/kernel/net/netfilter
rm -rf /lib/modules/*/kernel/net/netrom
rm -rf /lib/modules/*/kernel/net/rose
rm -rf /lib/modules/*/kernel/net/sctp
rm -rf /lib/modules/*/kernel/net/tipc
rm -rf /lib/modules/*/kernel/net/x25
rm -rf /lib/modules/*/kernel/sound

# remove blacklisted kernel modules
sed -n 's/^blacklist[[:space:]]\+\([^[:space:]]\+\).*/\1/p' /etc/modprobe.d/* |
	while read i; do
		/.host/find /lib/modules/ -type f -name "$i.ko" -delete
	done

# remove rpmdb for size reasons (aufs root allows package installation)
rm -rf /var/lib/rpm/*

# remove apt data files
rm -rf /var/cache/apt /var/lib*/apt

# remove translations
rm -rf /usr/share/locale /usr/lib/locale

# udev needed this
ln -sf /proc/mounts /etc/mtab

# ensure depmod
for i in /lib/modules/*; do
	/sbin/depmod -a -F /boot/System.map-${i##*/} ${i##*/}
done

# remove kernel images
rm -rf /boot/*

# remove unneeded pixmaps
rm -f /usr/share/pixmaps/xterm*

# remove desktop files
rm -f /usr/share/applications/*

# remove X11 locales
rm -Rf /usr/share/X11/locale/

# remove /usr/local
rm -Rf /usr/local/*

# remove all headers
rm -Rf /usr/include/*

# drop files in /sbin...
rm -f /sbin/udevconvertdb
rm -f /sbin/tcb_*
rm -f /sbin/installinfo
rm -f /sbin/installkernel
rm -f /sbin/glibc_*

# ...and in /lib
rm -fR /lib/mkinitrd

# remove skel
rm -fR /etc/skel*

# cleanup /etc
rm -Rf /etc/firsttime.d
rm -Rf /etc/buildreqs
rm -Rf /etc/info-dir
